﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Threading;
using System.Web.Mvc;
using System.Web.Http;
using Mvc.Mailer;
using log4net;
using xConnected.Common.CategoryNew;
using xConnected.Common.Country;
using xConnected.Common.ExpertProfile;
using xConnected.Common.Language;
using xConnected.Core.Model;
using xConnected.Core.Model.ViewModel;
using xConnected.Infrastructure;
using xConnected.Mailers;
using xConnected.Service;



namespace xConnected.Controllers
{
    public class ExpertProfileApiController : BaseController<ExpertProfile>
    {
        private readonly CategoryService _categoryService;
        private readonly CategorySkillService _categorySkillService;
        private readonly CountryService _countryService;
        private readonly EducationService _educationService;
        private readonly EducationSkillService _educationSkillService;
        private readonly IndustryService _industryService;
        private readonly LanguageService _languageService;
        private readonly LanguageSkillService _languageSkillService;
        private readonly ExpertProfileService _profileService;
        private readonly TechnologyService _technologyService;
        private readonly TechnologySkillService _technologySkillService;
        private readonly UserService _userService;


        public ExpertProfileApiController(ExpertProfileService profileService,
                                       EducationSkillService educationSkillService,
                                       EducationService educationService,
                                       CountryService countryService,
                                       LanguageSkillService languageSkillService,
                                       TechnologySkillService technologySkillService,
                                       TechnologyService technologyService,
                                       CategorySkillService categorySkillService,
                                       CategoryService categoryService,
                                       UserService userService,
                                       LanguageService languageService,
                                       IndustryService industryService)
        {
            _profileService = profileService;
            _educationSkillService = educationSkillService;
            _educationService = educationService;
            _countryService = countryService;
            _languageSkillService = languageSkillService;
            _technologySkillService = technologySkillService;
            _technologyService = technologyService;
            _categorySkillService = categorySkillService;
            _categoryService = categoryService;
            _userService = userService;
            _languageService = languageService;
            _industryService = industryService;
        }

        public IEnumerable<ExpertProfile> ListAdvancedSearchAll(AdvancedSearchModelProfile profileModel)
        {
            ILog log = LogManager.GetLogger(GetType());
            
            if (profileModel.UserId == 1)
            {
                var user = _userService.GetUserByUsername(User.Identity.Name);
                profileModel.UserId = user.Id;
            }
            var page = _profileService.AdvancedPagedSearchedAll(profileModel);
            var profiles = page.Entities;
            //var profiles = { { Id = 1, Title = "Sandra" }, { Id = 2, Title = "Nadica" } };
            try
            {
                return profiles;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + Environment.NewLine + "Stack: " + ex.StackTrace, ex);
                return profiles;
            }
        }

        //public IEnumerable<ExpertProfile> ListAdvancedSearchAll(AdvancedSearchModelProfile profileModel)
        //{

        //    return new List<ExpertProfile> {
        //        new ExpertProfile {Id=1, Title="Star Wars", Description="Lucas"},
        //        new ExpertProfile {Id=1, Title="King Kong", Description="Jackson"},
        //        new ExpertProfile {Id=1, Title="Memento", Description="Nolan"}
        //    };
        //}
    }
}
